package com.luo.controller;

import com.alibaba.fastjson.JSON;
import com.luo.model.ResultObj;
import com.luo.model.SlideShowVO;
import com.luo.service.SlideShowService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 功能：管理员页面查询轮播图
 * 作者：Luo。
 * 日期：2024/3/18 8:58
 */
	@WebServlet("/querySlideShow")
public class QuerySlideShowController extends HttpServlet {
	SlideShowService slideShowService = new SlideShowService();

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		ResultObj resultObj = new ResultObj();
		List<SlideShowVO> slideShowVOS = null;
		try {
			slideShowVOS = slideShowService.querySlideShow();
		} catch (Exception e) {
			e.printStackTrace();
			resultObj.setCode("500");
			resultObj.setMsg("未知错误");
			String jsonString = JSON.toJSONString(resultObj);
			resp.getWriter().write(jsonString);
			resp.getWriter().close();
			return;
		}
		resultObj.setCode("200");
		resultObj.setMsg("查询成功");
		resultObj.setResult(slideShowVOS);
		String jsonString = JSON.toJSONString(resultObj);
		resp.getWriter().write(jsonString);
		resp.getWriter().close();
	}
}
